home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / ham / sattrk31.tgz / sattrack-3.1.tar / SatTrack / src / maketlex / maketlex.c
C/C++ Source or Header  |  1995-03-16  |  10KB  |  288 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*  Title       : maketlex.c                                                  */
  4. /*  Author      : Manfred Bester                                              */
  5. /*  Date        : 13Feb94                                                     */
  6. /*  Last change : 15Mar95                                                     */
  7. /*                                                                            */
  8. /*  Synopsis    : This program generates the data file 'tlex.dat' which is    */
  9. /*                a concatenation of various other files with two-line        */
  10. /*                Keplerian element sets in the order listed below in the     */
  11. /*                source code.                                                */
  12. /*                                                                            */
  13. /*  Input files : tlelist.dat                                                 */
  14. /*  Output files: index.dat, satlist_all.dat, tlex.dat                        */
  15. /*                                                                            */
  16. /*                                                                            */
  17. /*  SatTrack is Copyright (c) 1992, 1993, 1994, 1995 by Manfred Bester.       */
  18. /*  All Rights Reserved.                                                      */
  19. /*                                                                            */
  20. /*  Permission to use, copy, and distribute SatTrack and its documentation    */
  21. /*  in its entirety for educational, research and non-profit purposes,        */
  22. /*  without fee, and without a written agreement is hereby granted, provided  */
  23. /*  that the above copyright notice and the following three paragraphs appear */
  24. /*  in all copies. SatTrack may be modified for personal purposes, but        */
  25. /*  modified versions may NOT be distributed without prior consent of the     */
  26. /*  author.                                                                   */
  27. /*                                                                            */
  28. /*  Permission to incorporate this software into commercial products may be   */
  29. /*  obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,    */
  30. /*  Berkeley, CA 94709, USA. Note that distributing SatTrack 'bundled' in     */
  31. /*  with ANY product is considered to be a 'commercial purpose'.              */
  32. /*                                                                            */
  33. /*  IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, */
  34. /*  SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF   */
  35. /*  THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED  */
  36. /*  OF THE POSSIBILITY OF SUCH DAMAGE.                                        */
  37. /*                                                                            */
  38. /*  THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT      */
  39. /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A   */
  40. /*  PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"      */
  41. /*  BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, */
  42. /*  UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                  */
  43. /*                                                                            */
  44. /******************************************************************************/
  45.  
  46. #include <stdio.h>
  47. #include <math.h>
  48. #include <string.h>
  49.  
  50. #ifndef STDLIB
  51. #include <stdlib.h>
  52. #endif
  53.  
  54. #include "sattrack.h"
  55.  
  56. #ifdef HPTERM
  57. #include "hpterm.h"
  58. #else
  59. #include "vt100.h"
  60. #endif
  61.  
  62. /******************************************************************************/
  63. /*                                                                            */
  64. /* external functions                                                         */
  65. /*                                                                            */
  66. /******************************************************************************/
  67.  
  68. extern double getElement();
  69.  
  70. /******************************************************************************/
  71. /*                                                                            */
  72. /* structures                                                                 */
  73. /*                                                                            */
  74. /******************************************************************************/
  75.  
  76. #define MAXFILES 100
  77.  
  78. typedef struct {
  79.     char tleFile[80];
  80.     } listType;
  81.  
  82. listType list[MAXFILES];
  83.  
  84. /******************************************************************************/
  85. /*                                                                            */
  86. /* main program                                                               */
  87. /*                                                                            */
  88. /******************************************************************************/
  89.  
  90. void main(argc,argv)
  91.  
  92. int  argc;
  93. char *argv[];
  94.  
  95. {
  96.     long satNum, satNumList[MAXSATS];
  97.  
  98.     int  i, k, K, duplFlag, verboseFlag, numTleFiles;
  99.  
  100.     char data[100], tle[100], tleLine0[100], tleLine1[100], tleLine2[100];
  101.     char str[100];
  102.     char inputFile[100], outputFile[100], indexFile[100], listFile[100];
  103.     char satlistFile[100];
  104.     char *strpHome, *getenv();
  105.  
  106.     FILE *InputFile, *OutputFile, *ListFile, *IndexFile, *SatlistFile;
  107.  
  108.     verboseFlag = (argc == 2 && !strncmp(argv[1],"-v",2)) ? TRUE : FALSE;
  109.  
  110. #ifdef HOMEDIR
  111.     strpHome = getenv("HOME");
  112. #else
  113.     strpHome = SATDIR;
  114. #endif
  115.  
  116.     sprintf(data,"%s/%s",strpHome,DATA);
  117.     sprintf(indexFile,"%s/index.dat",data);
  118.     sprintf(listFile,"%s/tlelist.dat",data);
  119.     sprintf(satlistFile,"%s/satlist_all.dat",data);
  120.  
  121.     sprintf(tle,"%s/%s",strpHome,TLE);
  122.     sprintf(outputFile,"%s/tlex.dat",tle);
  123.  
  124.     if ((OutputFile = fopen(outputFile,"w")) == NULL)
  125.     {
  126.         doBeep(); nl(); reverseBlink();
  127.         printf("can't write %s\n",outputFile);
  128.         normal(); nl();
  129.         exit(-1);
  130.     }
  131.  
  132.     else
  133.         fclose(OutputFile);
  134.  
  135.     if ((IndexFile = fopen(indexFile,"w")) == NULL)
  136.     {
  137.         doBeep(); nl(); reverseBlink();
  138.         printf("can't write %s\n",indexFile);
  139.         normal(); nl();
  140.         exit(-1);
  141.     }
  142.  
  143.     else
  144.         fclose(IndexFile);
  145.  
  146.     if ((SatlistFile = fopen(satlistFile,"w")) == NULL)
  147.     {
  148.         doBeep(); nl(); reverseBlink();
  149.         printf("can't write %s\n",satlistFile);
  150.         normal(); nl();
  151.         exit(-1);
  152.     }
  153.  
  154.     else
  155.         fclose(SatlistFile);
  156.  
  157.     if ((ListFile = fopen(listFile,"r")) == NULL)
  158.     {
  159.         doBeep(); nl(); reverseBlink();
  160.         printf("'%s' not found\n",listFile);
  161.         normal(); nl();
  162.         exit(-1);
  163.     }
  164.  
  165.     numTleFiles = 0;
  166.  
  167.     while (fgets(str,80,ListFile))
  168.     {
  169.         str[strlen(str) - 1] = '\0';
  170.         strcpy(list[numTleFiles].tleFile,str);
  171.         numTleFiles++;
  172.     }
  173.  
  174.     if (verboseFlag)
  175.     {
  176.         printf("\ngot %d file names with tle data from tlex.dat\n\n",
  177.             numTleFiles);
  178.  
  179.         for (i = 0; i < numTleFiles; i++)
  180.         {
  181.             printf("%2d:  %s\n",i+1,list[i].tleFile);
  182.         }
  183.  
  184.         printf("\n");
  185.     }
  186.  
  187.     K = 0;
  188.  
  189.     for (i = 0; i < numTleFiles; i++)
  190.     {
  191.         sprintf(inputFile,"%s/%s",tle,list[i].tleFile);
  192.  
  193.         if (verboseFlag)
  194.             printf("\nreading from '%s'\n",list[i].tleFile);
  195.  
  196.         if ((InputFile = fopen(inputFile,"r")) == NULL)
  197.         {
  198.             doBeep(); nl(); reverseBlink();
  199.             printf("'%s' not found\n",inputFile);
  200.             normal(); nl();
  201.             exit(-1);
  202.         }
  203.  
  204.         else
  205.             fclose(InputFile);
  206.  
  207.         InputFile   = fopen(inputFile, "r");
  208.         OutputFile  = fopen(outputFile,"a");
  209.         IndexFile   = fopen(indexFile,"a");
  210.         SatlistFile = fopen(satlistFile,"a");
  211.  
  212.         while (fgets(tleLine0,80,InputFile) &&  K < MAXSATS)
  213.         {
  214.             if (!strncmp(tleLine0,TLEHEADER,10))       /* discard header line */
  215.                 fgets(tleLine0,80,InputFile);
  216.  
  217.             fgets(tleLine1,80,InputFile);
  218.             fgets(tleLine2,80,InputFile);
  219.  
  220.             satNum   = (long) (getElement(tleLine1,3,7) + ONEPPM);
  221.             duplFlag = FALSE;
  222.  
  223.             for (k = 0; k < K; k++)
  224.             {
  225.                 if (satNum == satNumList[k])
  226.                     duplFlag = TRUE;
  227.             }
  228.  
  229.             if (!duplFlag)
  230.             {
  231.                 fprintf(OutputFile,"%s",tleLine0);
  232.                 fprintf(OutputFile,"%s",tleLine1);
  233.                 fprintf(OutputFile,"%s",tleLine2);
  234.                 fprintf(IndexFile,"%-6ld  %s",satNum,tleLine0);
  235.                 fprintf(SatlistFile,"%ld\n",satNum);
  236.  
  237.                 satNumList[K] = satNum;
  238.                 K++;
  239.             }
  240.  
  241.             else
  242.             {
  243.                 if (verboseFlag)
  244.                     printf("  duplicate entry: %-5ld  %s",satNum,tleLine0);
  245.             }
  246.         }
  247.  
  248.         fclose(InputFile);
  249.         fclose(OutputFile);
  250.         fclose(IndexFile);
  251.         fclose(SatlistFile);
  252.     }
  253.  
  254.     if (verboseFlag)
  255.         printf("\n'tlex.dat' contains %d two-line element sets.\n\n",K);
  256. }
  257.  
  258. /******************************************************************************/
  259. /*                                                                            */
  260. /* getElement: returns double of orbital element out of ASCII string          */
  261. /*                                                                            */
  262. /******************************************************************************/
  263.  
  264. double getElement(gstr,gstart,gstop)
  265.  
  266. int  gstart, gstop;
  267. char gstr[80];
  268.  
  269. {
  270.     int  k, glength;
  271.     char gestr[80];
  272.  
  273.     glength = gstop - gstart + 1;
  274.  
  275.     for (k = 0; k <= glength; k++)
  276.         gestr[k] = gstr[gstart+k-1];
  277.  
  278.     gestr[glength] = '\0';
  279.  
  280.     return((double) atof(gestr));
  281. }
  282.  
  283. /******************************************************************************/
  284. /*                                                                            */
  285. /* End of program maketlex.c                                                  */
  286. /*                                                                            */
  287. /******************************************************************************/
  288.